package work20241126_27;

import java.util.Arrays;

/**
 * @author zdl
 * @date 2024/11/26
 */
public class Demo30 {
    public static void main(String[] args) {
        //实现一个方法，求两个数组的交集。
        int[] arr = {1, 2, 3, 4, 5};
        int[] arr1 = {2, 3, 4, 7};
        int[] arr2 = intersection(arr,arr1);
        System.out.println(Arrays.toString(arr2));
    }
    public static int[] intersection(int[] arr,int[] arr1){
        int count = 0;
        int[] tempArr = new int[arr.length + arr1.length];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr1.length; j++) {
                if (arr[i] == arr1[j]) {
                    tempArr[count++] = arr[i];

                }
            }
        }
        int[] newArr = new int[count];
        System.out.println(count);
        for (int i = 0; i < newArr.length; i++) {
            newArr[i] = tempArr[i];
        }
        return newArr;
    }

}
